<template>
  <div>
    <el-form ref="form" class="form-box" :rules="rules" :model="tenant" label-width="80px">
      <el-form-item label="企业名称" prop="name">
        <el-input v-model="tenant.name"></el-input>
      </el-form-item>
      <el-form-item label="客服网址" prop="site">
        <el-input v-model="tenant.site"></el-input>
      </el-form-item>
      <el-form-item label-width="0" style="text-align: center">
        <el-button type="primary" @click="onSubmit">保存修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {saveTenant,getTenantById} from "@/api/auth/tenant";

export default {
  name: "tenant",
  data() {
    return {
      tenant:{},
      rules: {
        name: [
          {required: true, message: '请输入企业名称', trigger: 'blur'}
        ],
        site: [
          {required: true, message: '请输入客服网址', trigger: 'blur'}
        ]
      }
    }
  },
  created() {
    getTenantById(this.$store.state.userInfo.tenantId).then(res => {
      if(res.code == 200) {
        this.tenant = res.data
      }
    })
  },
  methods: {
    onSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          saveTenant(this.tenant).then(res => {
            if(res.code == 200) {
              this.$message.success('保存成功')
            }
          })
        } else {
          return false;
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
.form-box {
  padding: 30px;
  width: 60%;
}

@media(max-width: 679px) {
  .form-box {
    width: 100%;
    padding: 15px;
    box-sizing: border-box;
  }
}
</style>

